package com.example.mdoncall;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 
 * @author Anthony Maniquiz & Laine Nicolas (Smart Telecom Inc. OJT) 
 * @version 1
 * 
 */ 

public class RelatedPatientsActivity extends Activity{
	
	public void onCreate(Bundle bundle){
		super.onCreate(bundle);
		setContentView(R.layout.activity_relatedpatients);
		setOrientation();
		
		Intent intent = getIntent();
		String strNumber = intent.getStringExtra("search");
		
		PersonDbHelper db = new PersonDbHelper(this);
		List<Contact> contacts = db.getAllContacts();
		
		LinearLayout llyout = (LinearLayout) findViewById(R.id.relatedPlayout);
		
		for(Contact cn: contacts){
			if(cn.getPhoneNumber().equalsIgnoreCase(strNumber)){
				final int id = cn.getID();
				TextView  tv = new TextView(this);
				tv.setTextSize(25);
				tv.setId(id);
				tv.setPadding(5, 5, 5, 5);
				tv.setBackgroundResource(R.drawable.back);
				tv.setText(cn.getFname() + " " + cn.getLname());
				tv.setOnClickListener(new OnClickListener(){
					public void onClick(View v) {
					goSearch(v, id);
					}
				});
		        llyout.addView(tv);
			}
		}
	}
	
	public void goSearch(View view, int id){
		Intent intent = new Intent(this, ViewPatientActivity.class);
		
		intent.putExtra("search", id);
		startActivity(intent);
	}
	
	protected void setOrientation() {
    	int current = getRequestedOrientation();
    	if(current != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
    		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    	}
    }
}
